<template>
	<view class="page-block">
		<view class="header">
			<image src="/static/search.png"  class="search-img"></image>
			<input type="text" value="" placeholder="搜索预告" maxlength="10"
			confirm-type="search" @confirm="searchMe"/>
		</view>
		<view class="movielists page-block">
			<view class="movie-item" v-for="(item,index) in movies" :key="index">
				<image :src="item.cover" mode="" @click="gomovie(item.id)"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import common from '../../common/common.js'
	export default {
		data() {
			return {
				movies:[],
				keywords:"",
				page:1,
				totalPages:1
			}
		},
		onLoad() {
			uni.showLoading({
				title:"数据加载中"
			})
			this.getmovieitems(this.keywords,this.page,this.totalPages)
		},
		onReachBottom() {
			var page = this.page  + 1
			var keywords = this.keywords
			var totalPages = this.totalPages
			
				
			if(page>totalPages){
				return
			}
			
			this.getmovieitems(keywords,page,15)
		},
		methods: {
			getmovieitems(keywords,page,pageSize){
				uni.request({
					url:common.serverUrl+'/search/list?keywords='+keywords+'&page='+page+'&pageSize='+'pageSize',
					method:"POST",
					success:(res)=>{
						console.log(res)
						var templist = res.data.data.rows
						this.movies= this.movies.concat(templist)
						this.totalPages = res.data.data.total
						this.page = page
						uni.hideLoading()
					}
				})
			},
				
			searchMe(e){
				console.log(e.detail.value)
				this.keywords = e.detail.value
				this.movies = []
				this.getmovieitems(e.detail.value,1,15)
			},
				
			gomovie(id){
				console.log(id)
				uni.navigateTo({
					url:'../movie/movie/movie?id='+id
				})
			}
		}
	}
</script>

<style>
	@import url("./search.css");
</style>
